home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Vault: The Gold Collection
/
Software Vault - The Gold Collection (American Databankers) (1993).ISO
/
cdr22
/
dtkclk11.zip
/
CLKDEFS.H
< prev
next >
Wrap
Text File
|
1993-05-05
|
4KB
|
116 lines
/*
* Program to handle a DTK clock/calendar board based on the OKI 5832 chip.
*
* (C) Copyright 1989 Richard B. Wales.
* All Rights Reserved. This program may be freely copied and
* distributed for commercial or non-commercial use, provided:
* (1) this source code is included in any distribution;
* (2) all copyright notices are retained intact; and
* (3) no charge (other than a reasonable copying or communications
* charge) is assessed.
*/
#include <dos.h>
/*
* 8255 (PPI) I/O port addresses.
* The "base" address is determined by the DTK circuit board layout,
* as is the allocation of the PPI's three data ports (A, B, and C)
* to the various functions on the 5832 clock/calendar chip.
*/
#define CLKBASE 0x020c
#define CLKDATA (CLKBASE+0) /* PPI port A (clock data) */
#define CLKADDR (CLKBASE+1) /* PPI port B (clock address) */
#define CLKCTRL (CLKBASE+2) /* PPI port C (clock control) */
#define PPICTRL (CLKBASE+3) /* PPI control port */
/*
* Values for PPICTRL.
* These values control the read/write status of the PPI's data ports.
* Consult the 8255 technical specs for more info.
*/
#define PPI_READ 0x90 /* read port A; write B and C */
#define PPI_WRITE 0x80 /* write ports A, B, and C */
/*
* Values for CLKCTRL (to signal lines on 5832 chip).
* The allocation of the bits of PPI port C to the 5832's signal lines
* is determined by the DTK circuit board layout.
*/
#define CLK_SELECT 0x80 /* clock chip select */
#define CLK_HOLD 0x40 /* hold clock value for I/O */
#define CLK_READ 0x20 /* read from clock */
#define CLK_WRITE 0x10 /* write to clock */
/*
* Macros for reading from the clock.
*/
#define READY_TO_READ { outportb (CLKCTRL, CLK_SELECT + CLK_READ); }
#define READ_CLOCK(x) { outportb (CLKADDR, x); \
CLK_READ_DELAY; \
clkdata[x] = inportb (CLKDATA) & 0xf; \
}
#define DONE_READING { outportb (CLKCTRL, 0); }
/*
* Macros for writing to the clock.
*/
#define READY_TO_WRITE { outportb (CLKCTRL, CLK_SELECT+CLK_HOLD); \
CLK_HOLD_DELAY; \
}
#define WRITE_CLOCK(x) { outportb (CLKADDR, x); \
outportb (CLKDATA, clkdata[x]); \
CLK_WRITE_DELAY; \
outportb (CLKCTRL, CLK_SELECT+CLK_HOLD+CLK_WRITE); \
CLK_WRITE_DELAY; \
outportb (CLKCTRL, CLK_SELECT+CLK_HOLD); \
}
#define DONE_WRITING { outportb (CLKCTRL, 0); }
/*
* Time delay loops.
* Required delays as specified in the OKI MSM5832RS documentation:
* Hold setup (tHS): 150 usec
* Read access (tRA): 6 usec
* Write pulse (tWW): 1 usec
*/
#define CLK_HOLD_DELAY { int x; for (x = 250; x > 0; x--) ; }
#define CLK_READ_DELAY { int x; for (x = 10; x > 0; x--) ; }
#define CLK_WRITE_DELAY { int x; for (x = 2; x > 0; x--) ; }
/*
* Data structure for clock values.
* All values are in two-digit BCD form.
*/
struct clockval
{ unsigned char cv_century,
cv_year,
cv_month,
cv_day,
cv_hour,
cv_minute,
cv_second;
};
#define NULL_CLOCK (struct clockval *) 0
#define NULL_DATE (struct date *) 0
#define NULL_TIME (struct time *) 0
#define NULL_CLOCK_P (struct clockval **) 0
#define NULL_DATE_P (struct date **) 0
#define NULL_TIME_P (struct time **) 0
/* in READ.C */
struct clockval *read_clock (void);
void clock_to_time (struct clockval *cv,
struct date **da,
struct time **ti);
/* in WRITE.C */
struct clockval *write_clock (struct clockval *cv);
void time_to_clock (struct date *da,
struct time *ti,
struct clockval **cv);
/* in CAL.C */
void advance_time (struct clockval *cv,
int seconds);
int day_of_the_week (struct clockval *cv);